package com.sddz.pacs.service.impl;

import com.sddz.pacs.entity.SysRole;
import com.sddz.pacs.entity.SysRolePermission;
import com.sddz.pacs.mapper.SysRolePermissionMapper;
import com.sddz.pacs.service.SysRolePermissionService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 系统角色权限表 服务实现类
 * </p>
 *
 * @author 时代电子
 * @since 2018-05-16
 */
@Service
public class SysRolePermissionServiceImpl extends ServiceImpl<SysRolePermissionMapper, SysRolePermission> implements SysRolePermissionService {

    @Override
    /**
     * 添加角色权限
     * @param sysRole
     * @return boolean true= 成功， false = 失败
     */
    public boolean saveRolePermission(SysRole sysRole) {

        if(sysRole.getPermissions()!=null && sysRole.getPermissions().size()>0){
            Map map=new HashMap();
            map.put("roleId",sysRole.getId());
            map.put("list",sysRole.getPermissions());
            boolean result = this.baseMapper.save(map);
            return result;
        }
        return false;
    }

    @Override
    public Set<String> getPermissionsByRoleId(String roleId) {
        Set<String> permission = null;
        permission = this.baseMapper.getPermissionsByRoleId(roleId);
        return permission;
    }
}
